/**
 * 
 */
package org.perfect.batch.partition;

import java.util.Set;

import org.apache.dubbo.config.annotation.DubboReference;
import org.perfect.batch.api.IBatchService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.partition.support.AbstractPartitionHandler;

/**
 * @author billmse
 *
 */
public class RemotePartitionHandler extends AbstractPartitionHandler {

	@DubboReference(injvm = false, check = false)
	private IBatchService service;

	private Logger logger = LoggerFactory.getLogger(getClass());

	@Override
	protected Set<StepExecution> doHandle(StepExecution masterStepExecution, Set<StepExecution> partitionStepExecutions)
			throws Exception {
		for (StepExecution stepExecution : partitionStepExecutions) {
			if (logger.isInfoEnabled()) {
				logger.info("{}", stepExecution);
			}
			service.executeStep(stepExecution.getJobExecutionId(), stepExecution.getId());
		}
		return partitionStepExecutions;
	}

}
